import re
from playwright.sync_api import Playwright, sync_playwright, expect


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    page = context.new_page()
    page.goto("https://www.baidu.com/", timeout=30000)
    page.get_by_role("textbox", name="外交部驳斥鲁比奥涉华言论").click()
    page.get_by_role("textbox", name="外交部驳斥鲁比奥涉华言论").fill("PO设计模式")
    page.get_by_role("button", name="百度一下").click()
    page.get_by_role("link", name="高级搜索").click()
    page.locator("#adv_keyword").click()
    page.locator("input[name=\"q6\"]").click()
    page.locator("input[name=\"q6\"]").fill("baidu")
    page.locator("input[name=\"q4\"]").click()
    page.locator("input[name=\"q4\"]").fill("")
    page.locator("#adv_keyword").click()
    page.locator("#adv_keyword").fill("po")
    with page.expect_popup() as page1_info:
        page.get_by_role("button", name="高级搜索").click()
    page1 = page1_info.value

    # ---------------------
    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)
